﻿//------------------------------------------------------------------------------
// <copyright file="Weapon.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using Microsoft.Internal.GamesTest.Rpc.Server;

namespace Rpc.CSharpSample
{
    /// <summary>
    /// Defines a weapon used by the player to test RPC server.
    /// </summary>
    public class Weapon
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Weapon"/> class.
        /// </summary>
        public Weapon()
        {
        }

        /// <summary>
        /// Gets or sets the damage inflicted by this weapon.
        /// </summary>
        public uint Damage
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the damage modifier for damage inflicted.
        /// </summary>
        public double Modifier
        {
            get;
            set;
        }

        /// <summary>
        /// Deserializes a weapon object form an archive.
        /// </summary>
        /// <param name="archive">Archive containing data used to re-construct the Weapon object.</param>
        /// <returns>The Weapon object read from the archive.</returns>
        public static Weapon FromRpcArchive(RpcArchive archive)
        {
            Weapon weapon = new Weapon();
            weapon.Damage = archive.GetNamedDwordValue("damage");
            weapon.Modifier = archive.GetNamedDoubleValue("modifier");

            return weapon;
        }

        /// <summary>
        /// Serializes a weapon object to an archive.
        /// </summary>
        /// <returns>Archive containing data used to reconstruct the Weapon object.</returns>
        public RpcArchive ToRpcArchive()
        {
            RpcArchive archive = new RpcArchive();
            archive.SetNamedDwordValue("damage", this.Damage);
            archive.SetNamedDoubleValue("modifier", this.Modifier);

            return archive;
        }
    }
}
